package org.wkg.lesson05;

import java.util.Scanner;

public class Demo_504 {
    private volatile static int flag = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1启动....");
            while (flag == 0) {
                //一直运行
            }
            System.out.println("t1结束....");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2启动....");
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入一个非零数让程序停止运行:");
            flag = scanner.nextInt();
            System.out.println("t2结束....");
        });
        t1.start();
        t2.start();

    }
}

